//
//  LGJoinTeamCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/16.
//  加入团队列表

#import "LGJoinTeamCell.h"
#import "DCAvatar.h"
@interface LGJoinTeamCell() 
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *selectBtn;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
@end

@implementation LGJoinTeamCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [DCAvatarManager sharedAvatar].distanceBetweenAvatar = 2;
        [DCAvatarManager sharedAvatar].groupAvatarType = DCGroupAvatarWeChatType;
        [self createSubView];
    }
    return  self;
}


-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSString *title = [NSString stringWithFormat:@"%@（%@）",dataDic[@"title"],dataDic[@"nums"]];
    title = (title.length>12)?[NSString stringWithFormat:@"%@...",[title substringToIndex:12]]:title;
    self.titleLabel.text = title;
//    [self.iconView sd_setImageWithURL:[NSURL URLWithString:dataDic[@"icon"]] placeholderImage:defaultDoctorPic];
    [self.iconView dc_setImageAvatarWithGroupId:LGNSString(dataDic[@"teamid"]) Source:dataDic[@"iconAry"]];
}


-(void)setIsSelect:(BOOL)isSelect{
    _isSelect = isSelect;
    self.selectBtn.selected = isSelect;
}

-(void)selectBtnAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if(self.selectTeamAction){
        self.selectTeamAction(LGNSString(self.dataDic[@"teamid"]));
    }
}

-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.selectBtn];
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.tipView];
    [self.contentView addSubview:self.lineView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.top.equalTo(self.contentView).offset(-10);
        make.bottom.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.width.height.equalTo(@(viewPix(59)));
        make.centerY.equalTo(self.contentView);
    }];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.selectBtn.mas_right);
        make.width.height.equalTo(@(viewPix(42)));
        make.centerY.equalTo(self.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(20));
        make.right.equalTo(self.tipView.mas_left).offset(-viewPix(20));
        make.centerY.equalTo(self.contentView);
    }];
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-viewPix(32));
        make.centerY.equalTo(self.contentView);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView);
        make.right.equalTo(self.tipView);
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(@(0.5));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIButton *)selectBtn{
    if(!_selectBtn){
        _selectBtn = [UIButton buttonWithImage:@"unselect24" selectImage:@"selected24"];
        _selectBtn.frame = CGRectMake(0, 0, viewPix(58), viewPix(56));
        [_selectBtn addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]init];
        _iconView.backgroundColor = [UIColor colorWithString:@"#EEEEEE"];
        _iconView.cornerRidus = 5;
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _tipView;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E1E1E1"];
    }
    return _lineView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
